package anthology.daily_question._25_01;
//https://leetcode.cn/problems/shortest-subarray-with-or-at-least-k-ii/description/?envType=daily-question&envId=2025-01-17
public class _3097或值至少为K的最短子数组2 {
    class Solution {
        public int minimumSubarrayLength(int[] nums, int k) {
            int ans = Integer.MAX_VALUE;
            for (int i = 0; i < nums.length; i++) {
                int x = nums[i];
                if (x >= k) {
                    return 1;
                }
                for (int j = i - 1; j >= 0 && (nums[j] | x) != nums[j]; j--) {
                    nums[j] |= x;
                    if (nums[j] >= k) {
                        ans = Math.min(ans, i - j + 1);
                    }
                }
            }
            return ans == Integer.MAX_VALUE ? -1 : ans;
        }
    }
}
